package com.atguigu.ssm.service.impl;

import com.atguigu.ssm.entity.Schedule;
import com.atguigu.ssm.mapper.ScheduleMapper;
import com.atguigu.ssm.service.api.ScheduleService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true, rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public class ScheduleServiceImpl implements ScheduleService {

    @Resource
    private ScheduleMapper scheduleMapper;

    @Transactional(readOnly = false)
    public void updateSchedule(Schedule schedule) {
        scheduleMapper.updateByPrimaryKey(schedule);
    }

    @Override
    public List<Schedule> getAllSchedule() {
        return scheduleMapper.selectAll();
    }

    @Override
    @Transactional(readOnly = false)
    public void removeSchedule(Long id) {
        scheduleMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional(readOnly = false)
    public void saveSchedule(Schedule schedule) {
        scheduleMapper.insert(schedule);
    }
}
